package com.bdqn.controller;

import com.bdqn.pojo.Role;
import com.bdqn.service.RoleService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/role")
@Tag(name = "角色控制器",description = "角色csgc")
public class RoleController {
    @Autowired
    RoleService roleService;
    /**
     * 获取所有角色
     */
    @GetMapping("getRoles")
    public List<Role> getRoles(){
        List<Role> list=roleService.getAll();
        return list;
    }
    /**
     * 根据用户编号获取用户拥有的角色的编号
     */
    @GetMapping("getUserRids")
    public List<Integer> getUserRids(int uid){
        List<Integer> list=roleService.getRids(uid);
        return list;
    }
    /**
     * 获取当前页角色相关的数据
     */
    @GetMapping("/getPageRoles")
    public PageInfo<Role> getPageRoles(int pageNum,int pageSize,String rname){
        PageInfo<Role> pageInfo=roleService.selectPage(pageNum,pageSize,rname);
        return pageInfo;
    }

    /**
     * 根据角色编号获取角色的权限菜单的编号
     */
    @GetMapping("getRoleMenus")
    public List<Integer> getRoleMenus(int rid){
        List<Integer> list=roleService.getRoleMids(rid);
        return list;
    }

    /**
     * 添加角色的菜单权限
     */
    @GetMapping("addRoleMenus")
    public int addRoleMenus(int rid,
              @RequestParam("mids")List<Integer>  mids){
        int row=roleService.addRoleMids(rid,mids);
        return row;
    }
}
